import Vue from 'vue'
import Vuex from 'vuex'
import home from './modules/home'
import user from './modules/user'
import { openconfApi } from '@/api'
import {
  API_HOST,
  PUSH_HOST,
  WEB_QQ,
  WEB_TEL,
  COPY_RIGHT,
  CHART_URL,
  VERIFY_CHAN,
  PROXY
} from "@/store/mutation-types";
Vue.use(Vuex)
// const debug = true
/* eslint-disable */
export default new Vuex.Store({
  modules: {
    home,
    user
  },
  state: {
    homeLogo: "",
    chartUrl: ""
  },
  mutations: {
    SET_HOMELOGO: (state, homeLogo) => {
      state.homeLogo = homeLogo
    },
    SET_CHARTURL: (state, chartUrl) => {
      state.chartUrl = chartUrl
    }
  },
  actions: {
    GET_CONF({ commit }) {
      return new Promise((resolve, reject) => {
        openconfApi().then(res => {
          if (res.code == 200) {
            commit("SET_CHARTURL", res.data.onlinechat);
            // console.log(res.data.apihost)
            Vue.ls.set(API_HOST, res.data.apihost, 7 * 24 * 60 * 60 * 1000);
            Vue.ls.set(CHART_URL, res.data.onlinechat, 7 * 24 * 60 * 60 * 1000);
            Vue.ls.set(WEB_TEL, res.data.webtel, 7 * 24 * 60 * 60 * 1000);
            Vue.ls.set(WEB_QQ, res.data.webqq, 7 * 24 * 60 * 60 * 1000);
            Vue.ls.set(COPY_RIGHT, res.data.copyright, 7 * 24 * 60 * 60 * 1000);
            Vue.ls.set(PUSH_HOST, res.data.push_host, 7 * 24 * 60 * 60 * 1000);
            Vue.ls.set(PROXY, res.data.proxy, 7 * 24 * 60 * 60 * 1000);
            // Vue.ls.set(VERIFY_CHAN, res.data.verify_chan, 7 * 24 * 60 * 60 * 1000);
            resolve(res)
          } else {
            reject(res)
          }
        })
      })
    }
  }
  // 是否开启vuex的debug模式
})
